﻿@using WB.Core.BoundedContexts.Designer.Resources
@using WB.Core.BoundedContexts.Designer.Views.Questionnaire.Pdf
@using WB.UI.Designer.Code
@using WB.UI.Designer.Utils
@model Main.Core.Entities.SubEntities.IStaticText
@{
    PdfQuestionnaireModel questionnaire = ViewBag.Questionnaire;
    var staticText = Model!;
}
<div class="static-text">
    <div class="static-text_container">
        <div class="question-meta">
            <div class="type">@PdfStrings.StaticText</div>
        </div>
        <div class="common-info">
            @if (questionnaire.StaticTextHasEnablementCondition(staticText))
            {
                <div class="condition">
                    <span>E</span>@questionnaire.GetExpressionExcerpt(staticText.ConditionExpression)
                    @if (questionnaire.ExpressionIsTooLong(staticText.ConditionExpression))
                    {
                    <div class="more">
                         <a href="#@questionnaire.GetConditionRef(staticText.PublicKey)">
                            @Pdf.Format(PdfStrings.AppendixLink, staticText.ConditionExpression.Length - questionnaire.Settings.ExpressionExcerptLength, questionnaire.GetEntityIndexInAppendix(staticText.PublicKey, "E"))
                        </a>
                    </div>
                    }
                </div>
            }
            @for (int i = 0; i < questionnaire.GetValidationsCount(staticText.ValidationConditions); i++)
            {
                var validation = staticText.ValidationConditions[i];
                <div class="validation-expression">
                    <span>V@(i + 1)</span>@questionnaire.GetExpressionExcerpt(validation.Expression)
                    @if (questionnaire.ExpressionIsTooLong(validation.Expression))
                    {
                        <div class="more">
                            <a href="#@questionnaire.GetValidationsRef(staticText.PublicKey)">
                                @Pdf.Format(PdfStrings.AppendixLink, validation.Expression.Length - questionnaire.Settings.ExpressionExcerptLength, questionnaire.GetEntityIndexInAppendix(staticText.PublicKey, "V"))
                            </a>
                        </div>
                    }
                </div>
                if (!string.IsNullOrWhiteSpace(@validation.Message))
                {
                    <div class="validation-message"><span>M@(i + 1)</span>@validation.Message</div>
                }
            }
        </div>
        <div id="@questionnaire.GetItemRef(staticText.PublicKey)" class="static_text">@Html.Raw(questionnaire.GetStaticText(staticText))</div>
        @if (questionnaire.StaticTextHasAttachedImage(staticText))
        {
            <figure>
                @*
                <img src="@Html.ContentAbsolute($"~/attachments/thumbnail/{questionnaire.GetAttachmentId(staticText)}/{questionnaire.Settings.AttachmentSize}")" alt="" />
                *@
                <img src="@Html.EmbedAttachmentImage(questionnaire.GetAttachmentId(staticText), questionnaire.Settings.AttachmentSize)" alt="" />
            </figure>
        }
    </div>
</div>
